<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./list.css">
    <style>
        *{padding: 0;margin: 0;box-sizing: border-box;}
    </style>
</head>
<body>
       <div id="app">
        <h1>TodoList</h1>
        <div class="todo-container">
            <input v-model="newTodo" @keyup.enter="addTodo" placeholder="Add a new task" class="todo-input">
            <button @click="addTodo" class="todo-button">Add</button>
        </div>
        <ul class="todo-list">
            <li v-for="(todo, index) in todos" :key="index" class="todo-item">
                {{ todo }}
                <button @click="deleteTodo" class="delete-button">Delete</button>
            </li>
        </ul>
    </div>
    <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> -->
    <script src="./vue.js"></script>
        <script>
            new Vue({
                el: '#app',
                data: {
                    newTodo: '', // 新任务的输入值
                    todos: [] // 任务列表
                },
                methods: {
                    addTodo() {
                        if (this.newTodo.trim() !== '') {
                            this.todos.push(this.newTodo.trim());
                            this.newTodo = ''; // 清空输入框
                        }
                    },
                    deleteTodo(index) {
                        this.todos.splice(index, 1); // 删除指定索引的任务
                    }
                }
            });
        </script>
</body>
</html>